﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.LongER.Framework.Utils;
using Com.LongER.UI;
using Com.LongER.Business.ZCH001;
using Com.LongER.Framework.Utils.LogUtils;

public partial class ZCH001 : ABasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //
        if (!this.Page.IsPostBack)
        {
            Label lblPageId = (Label)Master.FindControl("lblPageId");
            lblPageId.Text = "ZCH001";

            Label lblPageName = (Label)Master.FindControl("lblPageName");
            lblPageName.Text = "调度指示一览查询画面";

            //清空画面中的输入框
            #region
            proc清空_Init("0");

            #endregion
            //焦点位于调度指示号输入框中
            this.txt调度指示号.Focus();
        }
        //autocomplete
        this.txt品名.Text = this.hid品名.Value;
        this.txt指示状态.Text = this.hid指示状态.Value;
        this.txt车主.Text = this.hid车主.Value;
        this.txt所用车型.Text = this.hid所用车型.Value;
        this.txt装货地.Text = this.hid装货地.Value;
        this.txt卸货地.Text = this.hid卸货地.Value;
        this.txt指示状态.Text = this.hid指示状态.Value;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn主菜单_Click(object sender, EventArgs e)
    {
        Response.Redirect("/LongER/ZAH003.aspx");
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    protected void btn执行_Click(object sender, EventArgs e)
    {
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("DLNO", this.txt调度指示号.Text.ToString());
        dic.Add("PINMING_CD", this.txt品名CD.Text.ToString());
        dic.Add("SHIJI_STA", this.txt指示状态CD.Text.ToString());

        dic.Add("CHEPAI_NUM", this.txt车牌号.Text.ToString());
        dic.Add("CHEZHU", this.txt车主.Text.ToString());
        dic.Add("CHELIANG_XINGTAI", this.txt所用车型CD.Text.ToString());  //车辆形态
        dic.Add("HETONG_BIANHAO", this.txt合同编号.Text.ToString());
        dic.Add("ONO", this.txt订单号.Text.ToString());
        dic.Add("ZHUANGHUO", this.txt装货地.Text.ToString());
        dic.Add("XIEHUO", this.txt卸货地.Text.ToString());
        //
        if (this.hidPageNo.Value == string.Empty) this.hidPageNo.Value = "1";
        dic.Add("PAGE_NO", this.hidPageNo.Value);


        CZCH001 instance = new CZCH001();


        ZCH001DS.T_DIAODUDataTable dt = instance.GetT_DIAODU(dic);

        #region
        //总件数清空
        this.txt总件数.Text = string.Empty;
        //标题行以外全部移除
        for (int i = this.tblList.Rows.Count - 1; i >= 1; i--)
        {
            this.tblList.Rows.RemoveAt(i);
        }

        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        lblMsgCD.Text = "  ";

        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsg.Text = "  ";
        #endregion


        //查询结果不为空时
        if (dt.Count > 0)
        {
            this.txt总件数.Text = dt.Count.ToString();
        }
        //查询结果为空时
        else
        {
            String msg = MessageUtil.GetMessage("GTH002", "IGTH002001");

            lblMsgCD.Text = "IGTH002001";
            lblMsg.Text = msg;

            return;
        }

        int rowid = 0;
        //
        foreach (var dr in dt)
        {
            //创建新行
            TableRow row = new TableRow();
            if (rowid % 2 == 0) { row.CssClass = "odd"; } else { row.CssClass = "even"; }

            //选择
            TableCell cell = GetTableCell(width: 30, rowspan: 1);
            //
            RadioButton rb = new RadioButton();
            rb.ID = "rb" + rowid;
            rb.GroupName = "rad";
            if (rowid == 0) rb.Checked = true;

            cell.Controls.Add(rb);
            row.Cells.Add(cell);//插入单元格

            //调度指示号
            cell = GetTableCell(width: 50);
            cell.Text = dr.DLNO;
            row.Cells.Add(cell);

            //子号
            cell = GetTableCell(width: 100);
            cell.Text = dr.SUB_NO;
            row.Cells.Add(cell);

            //发货预定日
            cell = GetTableCell(width: 60);
            cell.Text = dr.FAHUO_YUDING_DAY + dr.FAHUO_YUDING_TIME +"时";
            row.Cells.Add(cell);

            //订单号
            cell = GetTableCell(width: 60);
            cell.Text = dr.ONO;
            row.Cells.Add(cell);

            //品名
            cell = GetTableCell(width: 50);
            cell.Text = dr.PINMING_CD + dr.PINMING_HANZI;
            row.Cells.Add(cell);

            //调度指示数量
            cell = GetTableCell(width: 65);
            cell.Text = dr.DIAODU_COUNTS;
            row.Cells.Add(cell);

            //调度指示重量
            cell = GetTableCell(width: 65);
            cell.Text = dr.DIAODU_WEIGHT;
            row.Cells.Add(cell);

            //车牌号
            cell = GetTableCell(width: 70);
            cell.Text = dr.CHEPAI_NUM;
            row.Cells.Add(cell);

            //所用车型
            cell = GetTableCell(width: 100);
            cell.Text = dr.CHELIANG_XINGTAI + dr.CHELIANG_XINGTAI_HANZI;
            row.Cells.Add(cell);

            //装货地
            cell = GetTableCell(width: 70);
            cell.Text = dr.ZHUANGHUO + dr.ZHUANGHUO_NAME;
            row.Cells.Add(cell);

            //卸货地
            cell = GetTableCell(width: 100);
            cell.Text = dr.XIEHUO + dr.XIEHUO_NAME;
            row.Cells.Add(cell);

            this.tblList.Rows.Add(row);


            rowid++;

        }

    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="width"></param>
    /// <param name="rowspan"></param>
    /// <returns></returns>
    private TableCell GetTableCell(int width = -1, int rowspan = 1, int colspan = 1)
    {
        //创建单元格对象
        TableCell cell = new TableCell();
        if (width != -1) cell.Width = width;
        if (rowspan > 1) cell.RowSpan = rowspan;
        if (colspan > 1) cell.ColumnSpan = colspan;
        return cell;
    }

    protected void proc清空_Init(string str处理区分)
    {
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsgCD.Text = "";
        lblMsg.Text = "";

        //控件的Enabled进行控制
        #region
        this.txt调度指示号.Enabled = true;

        this.txt发货预定日时_Day.Enabled = true;
        this.txt发货预定日时_Hour.Enabled = true;

        this.txt品名CD.Enabled = true;
        this.txt指示状态CD.Enabled = true;
        this.txt车牌号.Enabled = true;
        this.txt车主CD.Enabled = true;
        this.txt所用车型CD.Enabled = true;
        this.txt合同编号.Enabled = true;
        this.txt订单号.Enabled = true;
        this.txt装货地CD.Enabled = true;
        this.txt卸货地CD.Enabled = true;
        
        
        #endregion

        //控件的Text进行清空
        #region
        this.txt调度指示号.Text = string.Empty;

        this.txt发货预定日时_Day.Text = string.Empty;
        this.txt发货预定日时_Hour.Text = string.Empty;

        this.txt品名CD.Text = string.Empty;
        this.txt品名.Text = string.Empty;
        this.txt指示状态CD.Text = string.Empty;
        this.txt指示状态.Text = string.Empty;
        this.txt车牌号.Text = string.Empty;
        this.txt车主CD.Text = string.Empty;
        this.txt车主.Text = string.Empty;
        this.txt所用车型CD.Text = string.Empty;
        this.txt所用车型.Text = string.Empty;
        this.txt合同编号.Text = string.Empty;
        this.txt订单号.Text = string.Empty;
        this.txt装货地CD.Text = string.Empty;
        this.txt装货地.Text = string.Empty;
        this.txt卸货地CD.Text = string.Empty;
        this.txt卸货地.Text = string.Empty;
        this.txt总重量.Text = string.Empty;
        this.txt总数量.Text = string.Empty;

        //init
        if (str处理区分 == "0")
        {
        }
        //查询
        else if (str处理区分 == "1")
        {
        }


        #endregion

        //总件数
        this.txt总件数.Text = string.Empty;

        //数据表清空
        for (int i = this.tblList.Rows.Count - 1; i >= 1; i--)
        {
            this.tblList.Rows.RemoveAt(i);
        }

    }

    protected void btn清除_Click(object sender, EventArgs e)
    {
        //初期化处理
        #region
        //查询时，各个控件的属性进行控制
        proc清空_Init("1");
        #endregion
    }


}